<template>
  <div class="activity-item-container">
    <!-- 标题 -->
    <div class="title" @click="$router.push('/morelist/' + id)">
      <h2>{{ title }}</h2>
      <div class="activity-more">
        <span>更多</span>
        <span class="icon"></span>
      </div>
    </div>
    <!-- 推荐列表 -->
    <div class="activity-list">
      <div class="activity-item" v-for="item in itemList" :key="item.id" @click="$router.push('/feeds/' + item.id)">
        <!-- 图片 -->
        <div class="activity-pic">
          <div class="view-count">
            <span class="eye-icon"></span>
            <span class="count">{{ getCount(item.view_count) }}</span>
          </div>

          <van-image :src="item.covers[0].url">
            <template v-slot:loading>
              <img src="@/assets/goImages/8P.png" alt="" />
            </template>
          </van-image>
        </div>
        <!-- 描述 -->
        <div class="activity-desc">
          <h3>{{ item.tiny_title }}</h3>
          <div>{{ item.time }}</div>
          <span>{{ item.reason_text }}</span>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    id: Number,
    title: String,
    itemList: Array
  },
  methods: {
    getCount(count) {
      if (count < 10000) {
        return count
      } else {
        const re = /^\d+\.?\d?/
        let res = count / 10000 + ''
        return parseFloat(res.match(re)) + 'w'
      }
    }
  }
}
</script>

<style lang="less" scoped>
.activity-item-container {
  margin-top: 20px;
  padding: 10px;
  padding-bottom: 0;

  .title {
    display: flex;
    justify-content: space-between;
    align-items: center;

    h2 {
      font-size: 18px;
      font-weight: 700;
      color: #000;
    }
    .activity-more {
      display: flex;
      span {
        text-align: right;
        line-height: 20px;
        color: #989898;
        font-size: 16px;
      }
      span.icon {
        height: 17px;
        width: 30px;
        transform: rotateZ(-90deg) scale(0.5) translateY(-10px);
        background-repeat: no-repeat;
        background-size: 100% 100%;
        background-image: url('@/assets/arrow/f8.png');
      }
    }
  }
  .activity-list {
    margin-top: 15px;
    display: flex;
    flex-wrap: wrap;

    .activity-item {
      width: 50%;
      padding-bottom: 10px;
      margin-bottom: 20px;

      &:nth-of-type(odd) {
        padding-right: 5px;
      }
      &:nth-of-type(even) {
        padding-left: 5px;
      }

      .activity-pic {
        border-radius: 15px;
        overflow: hidden;
        position: relative;

        .view-count {
          position: absolute;
          bottom: 3px;
          right: 12px;
          display: flex;
          justify-content: space-between;
          align-items: center;
          z-index: 1;

          .eye-icon {
            height: 16px;
            width: 18px;
            background-image: url('@/assets/goImages/9p.png');
            background-size: 100% 100%;
            background-repeat: no-repeat;
          }

          .count {
            font-size: 12px;
            color: #fff;
            line-height: 20px;
            margin-left: 3px;
            font-weight: 600;
          }
        }
        img {
          width: 100%;
          height: 120px;
        }
      }
      .activity-desc {
        padding-top: 10px;

        h3 {
          width: 100%;
          font-size: 15px;
          font-weight: 600;
          color: #515151;
          padding-bottom: 10px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        div {
          color: #989898;
          font-size: 12px;
          padding-bottom: 15px;
          overflow: hidden;
          text-overflow: ellipsis;
          white-space: nowrap;
        }

        span {
          color: #76c1e7;
          background-color: #f5f1f1;
          padding: 5px;
          padding-left: 10px;
          font-size: 12px;
          font-weight: 500;
        }
      }
    }
  }
}
</style>
